package com.coffeeloversupportlibrary.coffeelover.domain.article.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.coffeeloversupportlibrary.R;
import com.coffeeloversupportlibrary.coffeelover.domain.article.entity.Article;
import com.coffeeloversupportlibrary.coffeelover.domain.article.type.SlideshowType;
import com.coffeeloversupportlibrary.databinding.SlideShowBinding;
import com.youth.banner.indicator.CircleIndicator;

import java.util.List;

/**
 * @author puyv
 * @createTime 2021/11/6 20:13
 * @projectName CoffeeLoverSupportLibrary
 * @className SlideshowAdapter.java
 * @description TODO
 */
public class SlideshowAdapter implements Adapter<List<SlideshowType>> {
    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent) {
        View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.slide_show,parent,false);
        SlideShowBinding slideShowBinding=SlideShowBinding.bind(view);
        return new SlideArticleViewHolder(slideShowBinding);
    }

    @Override
    public void onBindViewHolder(@NonNull List<SlideshowType> items, @NonNull RecyclerView.ViewHolder holder, int position) {

        SlideshowType item=items.get(position);
        List<Article> list=item.getItems();
        SlideshowListAdapter adapter=new SlideshowListAdapter(list);

        // setAdapter 返回 Banner 对象，可设置相关属性

        ((SlideArticleViewHolder)holder)
                .slideShowBinding
                .banner
                .setAdapter(adapter)
                .setBannerRound2(30)
                .setIndicator(new CircleIndicator(
                        ((SlideArticleViewHolder)holder)
                        .slideShowBinding
                        .banner
                        .getContext()));
    }

    static class SlideArticleViewHolder extends RecyclerView.ViewHolder{
        private SlideShowBinding slideShowBinding;
        public SlideArticleViewHolder(@NonNull SlideShowBinding slideShowBinding) {
            super(slideShowBinding.getRoot());
            this.slideShowBinding=slideShowBinding;
        }
    }
}
